package top.zhangjianyong.blog.manage.controller;

import java.util.concurrent.ExecutionException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.blog.annotation.Permission;
import top.zhangjianyong.blog.enums.RoleKeys;
import top.zhangjianyong.blog.params.blog.*;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.BlogService;

/**
 * 博客
 *
 * @author zhangjianyong
 * @since 2024/7/31 下午8:48
 */
@RequestMapping("/blog")
@RestController
@Permission(roles = {RoleKeys.ADMIN})
public class BlogController {

  private final BlogService blogService;

  public BlogController(BlogService blogService) {
    this.blogService = blogService;
  }

  @PostMapping("/page")
  public ApiResponse page(@RequestBody @Validated BlogPageParam param)
      throws ExecutionException, InterruptedException {
    return blogService.page(param);
  }

  @PostMapping("/get")
  public ApiResponse get(@RequestBody @Validated BlogGetParam param) {
    return blogService.get(param);
  }

  @PostMapping("/remove")
  public ApiResponse remove(@RequestBody @Validated BlogRemoveParam param) {
    return blogService.remove(param);
  }

  @PostMapping("/saveOrUpdate")
  public ApiResponse saveOrUpdate(@RequestBody @Validated BlogSaveOrUpdateParam param) {
    return blogService.saveOrUpdate(param);
  }

  @PostMapping("/push")
  public ApiResponse push(@RequestBody @Validated BlogPushParam param) {
    return blogService.push(param);
  }

  @PostMapping("/status/change")
  public ApiResponse statusChange(@RequestBody @Validated BlogStateChangeParam param) {
    return blogService.statusChange(param);
  }

  @PostMapping("/top")
  public ApiResponse top(@RequestBody @Validated BlogTopParam param) {
    return blogService.top(param);
  }
}
